//
//  DEHomeController.m
//  DE
//
//  Created by PEIYANG on 16/9/23.
//  Copyright © 2016年 YP. All rights reserved.
//


#import "DEHomeController.h"
#import "DEHomeHeaderView.h"
#import "DEHomeMainCell.h"
#import "KnowledgeNewsView.h"
#import "NowDaysRecView.h"
#import "DEHomePictureView.h"
#import "DEHomeSaying.h"

@interface DEHomeController ()<DEHomePictureViewDelegate>
@property(nonatomic,weak)NowDaysRecView *nView;
@property(nonatomic,strong)DEHomePictureView *picView;
@property(nonatomic,strong)DEHomeSaying *sayingView;
@property (nonatomic, weak)UICollectionView *collectionV;
@end

@implementation DEHomeController
static NSString * const ID = @"cellID";
static NSString * const ID1 = @"KViewID";
static NSString * const ID2 = @"NViewID";
static NSString * const ID3 = @"picViewID";
static NSString * const ID4 = @"sayViewID";
- (NowDaysRecView *)nView{
    if (!_nView) {
        _nView = [NowDaysRecView nowDaysRecView];
    }
    return _nView;
}

- (DEHomePictureView *)picView{
    if (!_picView) {
        _picView = [[DEHomePictureView alloc]init];
        _picView.delegate = self;
    }
    return _picView;
}

- (DEHomeSaying *)sayingView{
    if (!_sayingView) {
        _sayingView = [DEHomeSaying sayingView];
    }
    return _sayingView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupHeaderView];
    self.tableView.backgroundColor = YPRandomColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[DEHomeMainCell class] forCellReuseIdentifier:ID];

}


- (void)setupHeaderView{
    DEHomeHeaderView *headerV = [DEHomeHeaderView headerView];
    headerV.frame = CGRectMake(0, 0, self.view.yp_width, 340);
    headerV.ADImages = @[@"01",@"02",@"03",@"04"];
    headerV.orderingImages = @[@"launch_default_image_1",@"launch_default_image_2",@"launch_default_image_3",@"launch_default_image_1",@"launch_default_image_2",@"launch_default_image_3",@"launch_default_image_1",@"launch_default_image_2",@"launch_default_image_3"];
    
    self.tableView.tableHeaderView = headerV;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 6;
}
#pragma UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID1];
        KnowledgeNewsView *kView = [KnowledgeNewsView knowledgeNewView];
        kView.frame = CGRectMake(0, 0, YPScreenW, 150);
        
        [cell.contentView addSubview:kView];
        kView.backgroundColor = YPRandomColor;
        
        return cell;
        
    }else if(indexPath.row == 1){
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID2];
        _nView.frame = CGRectMake(0, 0, YPScreenW, self.nView.yp_height);
        
        [cell.contentView addSubview:_nView];

        return cell;
    }else if (indexPath.row == 5){
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID3];
        [cell.contentView addSubview:_picView];
        
        return cell;
    }else if (indexPath.row == 6){
        UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID4];
        [cell.contentView addSubview:_picView];
        
        return cell;
    }
    
    DEHomeMainCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 150;
    }else if (indexPath.row == 1){
        //调用get方法
        return self.nView.yp_height + margin;
    }else if (indexPath.row == 5){
        //调用get方法
        return self.picView.cellH;
    }else if (indexPath.row == 6){
        //调用get方法
        return self.picView.cellH;
    }
    
    DEHomeMainCell *cell = [[DEHomeMainCell alloc]init];
    return cell.cellH;
}

- (void)homePictureView:(DEHomePictureView *)pictureView btnClick:(UIButton *)btn{
    NSLog(@"点击了第%zd张图片",btn.tag);
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"%zd点击了第几行",indexPath.row);
}

@end
